package com.atguigu.srb.core.controller;


import com.atguigu.srb.core.pojo.entity.Lend;
import com.atguigu.srb.core.service.LendService;
import com.atguigu.srb.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author fun
 * @since 2021-10-29
 */
@RestController
@RequestMapping("/api/core/lend")
public class LendController {
    @Autowired
    LendService lendService;

    @PostMapping("/list")
    public R list() {
        List<Lend> lendList = lendService.getList();
        return R.ok().data("list", lendList);
    }

    @GetMapping("/show/{id}")
    public R show(@PathVariable("id") Long id) {
        Map<String, Object> lendDetail = lendService.show(id);
        return R.ok().data("lendDetail", lendDetail);
    }

    @GetMapping("/getInterestCount/{investAmount}/{lendYearRate}/{period}/{returnMethod}")
    public R getInterestCount(@PathVariable("investAmount") BigDecimal investAmount,
                              @PathVariable("lendYearRate") BigDecimal lendYearRate,
                              @PathVariable("period") BigDecimal period,
                              @PathVariable("returnMethod") BigDecimal returnMethod) {
        BigDecimal interestCount = lendService.getInterestCount(investAmount, lendYearRate, period, returnMethod);
        return R.ok().data("interestCount", interestCount);
    }

}

